/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Nov 4, 2013  3:26:39 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.database.dao.promis.impl
 * File Name : VwSyncDepositBlDaoImpl.java
 * TODO
 */
package com.tis.database.dao.promis.impl;

import java.util.Collections;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import promis.utility.CommonService;

import com.tis.database.dao.impl.AbstractDaoImpl;
import com.tis.database.dao.promis.VwSyncDepositBlDao;
import com.tis.database.entitys.promis.VwSyncDepositBl;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Nov 4, 2013 : 3:26:39 PM 
 * CreateBy=Chatree Siangklom
 * 
 * VwSyncDepositBlDaoImpl
 * TODO
 */
@SuppressWarnings("unchecked")
@Repository
public class VwSyncDepositBlDaoImpl extends AbstractDaoImpl<VwSyncDepositBl, String> implements VwSyncDepositBlDao {
	
	private static final Logger logging = LoggerFactory .getLogger(VwSyncDepositBlDaoImpl.class);
	
	/**
	 * Date =Nov 4, 2013 : 3:27:16 PM 
	 * CreateBy=Chatree Siangklom
	 * VwSyncDepositBlDaoImpl
	 * TODO
	 * @param entityClass
	 */
	protected VwSyncDepositBlDaoImpl() {
		super(VwSyncDepositBl.class);
	}

	/** (Javadoc)
	 * @see com.tis.database.dao.promis.VwSyncDepositBlDao#SearchByIsNotSend(java.lang.String, java.lang.String, java.lang.String, int)
	 * Date =Nov 4, 2013 : 3:27:04 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public List<VwSyncDepositBl> SearchByIsNotSend(String status, String syncIsstaging, String syncIssync, int maxResult) throws Exception {
		try{
			
			Session session = getCurrentSession();
			Query q = session.getNamedQuery(VwSyncDepositBl.findByIs);
			String query = q.getQueryString();
			
			if(!CommonService.IsNull(status))
				query += " And upper(c.status) IN ("+ status +") ";
			
			if(!CommonService.IsNull(syncIsstaging))
				query += " And upper(c.syncIsstaging) = :syncIsstaging ";
			
			if(!CommonService.IsNull(syncIssync))
				query += " And upper(c.syncIssync) = :syncIssync ";
			
			q = session.createQuery(query);
			
			if(!CommonService.IsNull(syncIsstaging))
				q.setParameter("syncIsstaging", CommonService.IsNullRString(syncIsstaging).toUpperCase());
			
			if(!CommonService.IsNull(syncIssync))
				q.setParameter("syncIssync", CommonService.IsNullRString(syncIssync).toUpperCase());
			
			if(maxResult > 0)
				q.setMaxResults(maxResult);
			
			List lst = q.list();
			logging.info("Size=" + CommonService.getSize(lst));
			List<VwSyncDepositBl> newlst = Collections.checkedList(q.list(), VwSyncDepositBl.class);
			
			if(CommonService.getSize(newlst) > 0 )
				return lst;
			else
				return null;
			
		}catch(Exception e){
			e.printStackTrace();
			logging.error(e.getMessage());
			throw e;
		}
	}
}
